package cn.com.taurus.controller.datatable;

import cn.com.taurus.biz.AdminLogBiz;
import cn.com.taurus.biz.FundHoldBiz;
import cn.com.taurus.biz.SystemNoticeBiz;
import cn.com.taurus.entity.AdminLog;
import cn.com.taurus.entity.FundHold;
import cn.com.taurus.entity.SystemNotice;
import cn.com.taurus.util.Log;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * @author zjw
 * @createTime 2021年6月28日
 * @remark 基金持有控制层
 * @version 1.0
 */
@Controller
public class FundHoldController {
    @Autowired
    FundHoldBiz fundHoldBiz;

    @RequestMapping("/fundHold")
    public String fundHold() {
        return "datatable/fundHold";
    }

    @RequestMapping("/updateFundHold")
    @Log(operation = "修改基金持有信息",type = 2)
    public String updateFundHold(@ModelAttribute FundHold fundHold){
        fundHoldBiz.fundHoldUpdate(fundHold);
        return "datatable/fundHold";
    }

    @RequestMapping("/deleteFundHold")
    @Log(operation = "删除基金持有信息",type = 3)
    public String deleteFundHold(Integer fhId){
        fundHoldBiz.fundHoldDelete(fhId);
        return "datatable/fundHold";
    }

    /**
     * 模糊查询
     * @param pageNum 几条
     * @param pageSize 数量
     * @return
     */
    @ResponseBody
    @RequestMapping("/selectDimFundHold")
    @Log(operation = "条件查询基金持有信息",type = 1)
    public HashMap selectDimFundHold(Integer pageNum, Integer pageSize,FundHold fundHold){
        System.out.println("11111");
        HashMap<String, Object> map = new HashMap<>();
        // 开启分页支持
        PageHelper.startPage(pageNum,pageSize);
        List<FundHold> rule = fundHoldBiz.selectDimFundHold(fundHold);
        System.out.println(fundHold);
        PageInfo<FundHold> pageInfo = new PageInfo<>(rule);
        System.out.println("数据："+pageInfo.getPages());
        map.put("code",0);
        map.put("msg","请求成功");
        //count：总数据条数
        map.put("count",pageInfo.getTotal());
        //data：数据
        map.put("data",pageInfo.getList());
        return map;
    }

    /**
     * 分页
     * @param pageNum
     * @param pageSize
     * @return
     */
    @ResponseBody
    @RequestMapping("/selectFundHold")
    public HashMap selectFundHold(Integer pageNum,Integer pageSize){
        HashMap<String, Object> map = new HashMap<>();
        // 开启分页支持
        PageHelper.startPage(pageNum,pageSize);
        List<FundHold> rule = fundHoldBiz.fundHoldSelectAll();
        PageInfo<FundHold> pageInfo = new PageInfo<>(rule);
        System.out.println("数据："+pageInfo.getPages());
        map.put("code",0);
        map.put("msg","请求成功");
        //count：总数据条数
        map.put("count",pageInfo.getTotal());
        //data：数据
        map.put("data",pageInfo.getList());
        System.out.println(map);
        return map;
    }
}
